﻿using System;
public class Node<T>
{
    public Node<T> Next { get; set; }
    public T Data { get; set; }
    public Node(T t)
    {
        Next = null;
        Data = t;
    }
}
public class GenericList<T>
{
    private Node<T> head;
    private Node<T> tail;
    public GenericList()
    {
        tail = head = null;
    }
    public Node<T> Head
    {
        get => head;
    }
    public void Add(T t)
    {
        try {
            Node<T> n = new Node<T>(t);      
            if (tail == null)
        {
            head = tail = n;
        }
        else
        {
            tail.Next = n;
            tail = n;
        }
        }
        catch
        {
            Console.WriteLine("链表元素不合法");
        }
 
    }
    public void ForEach(Action<T> action)
    {
        Node<T> t = head;
        while (t != null)
        {
            action(t.Data);
            t = t.Next;
        }

    }
     

}
class Solution
{
    static void Main(string[] args)
    {
        GenericList<int> list = new GenericList<int>();
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.ForEach(m => Console.WriteLine(m));
        int max = list.Head.Data;
        list.ForEach(m => max=max > m ?max :m);
        Console.WriteLine($"最大值为:{max}");
        int min = list.Head.Data;
        list.ForEach(m => min = min < m ? min : m);
        Console.WriteLine($"最小值为:{min}");
    }
}